#pragma once

#include "BasicObject.h"
#include "Agent.h"
#include "Goal.h"
#include "plannode.h"

#include <map>
#include "appraisal.h"
#include "planningstructs.h"

namespace BAA
{

	class Agent;
	class Goal;
	class Condition;
	class Appraisal;
	class PlanTreeNode;

	typedef std::multimap <std::string,Action*> ActionMultiMap;



	
	
	class PlanningEngine:public BasicObject
	{
	public:
		PlanningEngine(const std::string name):BasicObject(name)
		{

		}

		~PlanningEngine()
		{

		}

		void Create();

		void Initialize(Agent * parent);

		void setParameters(int planLenghtMax, float careOfConsequence)
		{

			mMaxPlanLenght = planLenghtMax;
			mCareOfConsequence = careOfConsequence;

		}

		void Clear(){}

		bool BuildPlanTree(Agent * agent, Goal *goal);

		void AddAction(std::string postcondition, Action* action);

		PlanTreeNode* Update(Agent* agent, Goal* goal);

		// the current plan
		std::vector<Action*>* Plan() { return &mPlan; }
		//void Plan(vector<Action*> val) { mPlan = val; }

		Goal * CurrentGoal() const { return mCurrentGoal; }
		void CurrentGoal(Goal * val) { mCurrentGoal = val; }

		protected:

			Agent* mParent;

		

			bool ResolveNode(std::string postcondition, PlanTreeNode* node);

			float BuildPlanAStar(PlanTreeNode* root, std::vector<Action*> * plan, int maxLength, float careOfConseqence);

			Goal * mCurrentGoal;

			ActionMultiMap      mActionMultiMap;

			PlanTreeNode * mPlanTree;
			std::vector<Action*> mPlan;

			int mMaxPlanLenght;
			float mCareOfConsequence;



	};// end class



	
	

}// end namespace
